#include "ExperimentTimeXml.h"
ExperimentTimeXml::ExperimentTimeXml()
{
    loadXmlData();
}

// xml数据读取
void ExperimentTimeXml::loadXmlData()
{
    QDomDocument doc;
    QString fileName = "ExperimentTime.xml";
    QFile file(fileName);
    if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
        qWarning() << "Failed to open file:" << fileName;
    }
    QString errorMsg;
    int errorLine, errorColumn;
    if (!doc.setContent(&file, &errorMsg, &errorLine, &errorColumn)) {
        qDebug() << "Error: " << errorMsg
                 << " at line: " << errorLine
                 << ", column: " << errorColumn;
        file.close();
    }
    file.close();
    QDomElement root = doc.documentElement();
    QDomNode n = root.firstChild();
    while (!n.isNull()) {
        QDomElement e = n.toElement(); // 尝试转换为元素
        if (!e.isNull()) {
            double textContent = e.text().toDouble();
            xmldata.append(textContent);
        }
        n = n.nextSibling();
    }
}

/**
 * @brief ExperimentTimeXml::getBarrier 挡板
 * @return
 */
double ExperimentTimeXml::getBarrier(){
    if(xmldata.length()>14){
        return  xmldata[0];
    }
    else{
        return 0;
    }
}

/**
 * @brief ExperimentTimeXml::getAcquisitionTarget 取放靶
 * @return
 */
double ExperimentTimeXml::getAcquisitionTarget(){
    if(xmldata.length()>14){
        return  xmldata[1];
    }
    else{
        return 0;
    }
}

/**
 * @brief ExperimentTimeXml::getClampingJaw 夹爪
 * @return
 */
double ExperimentTimeXml::getClampingJaw(){
    if(xmldata.length()>14){
        return  xmldata[2];
    }
    else{
        return 0;
    }
}

double ExperimentTimeXml::getTransmissionTarget(int module)
{
    if(xmldata.length()>14){
        return module==2?xmldata[3]:xmldata[8];
    }
    else{
        return 0;
    }
}

double ExperimentTimeXml::getSuctionTarget(){
    if(xmldata.length()>14){
        return xmldata[4];
    }
    else{
        return 0;
    }
}

double ExperimentTimeXml::getMoveTarget(){
    if(xmldata.length()>14){
        return xmldata[5];
    }
    else{
        return 0;
    }
}
double ExperimentTimeXml::getLockedUp(){
    if(xmldata.length()>14){
        return xmldata[6];
    }
    else{
        return 0;
    }
}
double ExperimentTimeXml::getFeed(){
    if(xmldata.length()>14){
        return xmldata[7];
    }
    else{
        return 0;
    }
}

double ExperimentTimeXml::getOpenTheLid(){
    if(xmldata.length()>14){
        return xmldata[9];
    }
    else{
        return 0;
    }
}

/**
 * @brief ExperimentTimeXml::getActivityTesting 活性检测
 * @return
 */
double ExperimentTimeXml::getActivityTesting(){
    if(xmldata.length()>14){
        return xmldata[10];
    }
    else{
        return 0;
    }
}

double ExperimentTimeXml::getRotaryCapClamp(){
    if(xmldata.length()>14){
        return xmldata[11];
    }
    else{
        return 0;
    }
}
double ExperimentTimeXml::getValve(){
    if(xmldata.length()>14){
        return xmldata[12];
    }
    else{
        return 0;
    }
}

double ExperimentTimeXml::getTurntable(){
    if(xmldata.length()>14){
        return xmldata[13];
    }
    else{
        return 0;
    }
}

double ExperimentTimeXml::getCoverTheLid(){
    if(xmldata.length()>14){
        return xmldata[14];
    }
    else{
        return 0;
    }
}
